/**
 *
 * @author Erivaldo Lourenco
 * @author Juliana Cavalcanti
 * 
 */

package br.ufal.ic.p3.Interface.funcionario;

import br.ufal.ic.p3.Interface.TelaErroCadastro;
import br.ufal.ic.p3.controle.ControleFuncionario;

import javax.swing.AbstractAction;
import javax.swing.JInternalFrame;

import java.awt.event.ActionEvent;

import javax.swing.Action;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import javax.swing.LayoutStyle.ComponentPlacement;
import java.awt.Color;
import javax.swing.ImageIcon;

public class CadastroFuncionario extends JInternalFrame {

	public CadastroFuncionario() {
		super("ProgNet - Cadastro Funcionario");
		getContentPane().setBackground(Color.WHITE);
		initComponents();
	}

	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		botaoVoltar = new javax.swing.JButton();
		botaoSalvar = new javax.swing.JButton();
		botaoSalvar.setAction(action);
		campoTelefone2 = new javax.swing.JTextField();
		labelTelefone2 = new javax.swing.JLabel();
		campoTelefone1 = new javax.swing.JTextField();
		labelTelefone1 = new javax.swing.JLabel();
		campoEmail = new javax.swing.JTextField();
		labelEmail = new javax.swing.JLabel();
		labelContato = new javax.swing.JLabel();
		campoCidade = new javax.swing.JTextField();
		labelCidade = new javax.swing.JLabel();
		campoRua = new javax.swing.JTextField();
		labelRua = new javax.swing.JLabel();
		labelEndereco = new javax.swing.JLabel();
		campoUF = new javax.swing.JComboBox();
		labelUF = new javax.swing.JLabel();
		campoBairro = new javax.swing.JTextField();
		labelBairro = new javax.swing.JLabel();
		campoCEP = new javax.swing.JTextField();
		labelCEP = new javax.swing.JLabel();
		campoSobrenome = new javax.swing.JTextField();
		labelSobrenome = new javax.swing.JLabel();
		campoNome = new javax.swing.JTextField();
		labelNome = new javax.swing.JLabel();
		labelRG = new javax.swing.JLabel();
		campoRG = new javax.swing.JTextField();
		campoCPF = new javax.swing.JTextField();
		campoCargo = new javax.swing.JTextField();
		labelCPF = new javax.swing.JLabel();
		labelCargo = new javax.swing.JLabel();
		labelDadosPessoais = new javax.swing.JLabel();
		barraMenu = new javax.swing.JMenuBar();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

		botaoVoltar.setIcon(new ImageIcon(CadastroFuncionario.class.getResource("/br/ufal/ic/p3/imagens/voltar.png"))); // NOI18N
		botaoVoltar.setText("Voltar");
		botaoVoltar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				setVisible(false);
			}
		});

		botaoSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource(
				"/br/ufal/ic/p3/imagens/salvar.png"))); // NOI18N
		botaoSalvar.setText("Salvar");
		botaoSalvar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				ControleFuncionario controle = new ControleFuncionario();
				System.out.println("retorno: " + campoCPF.getText());

				if (controle.verificarCpfCadastrado(campoCPF.getText()) != 1) {

					controle.adicionarFuncionario(campoNome.getText(),
							campoSobrenome.getText(), campoRG.getText(),
							campoCPF.getText(), campoCargo.getText(),
							campoRua.getText(), campoCidade.getText(),
							campoUF.getSelectedItem(), campoCEP.getColumns(),
							campoBairro.getText(), campoTelefone1.getText(),
							campoTelefone2.getText(), campoEmail.getText());
				} else {

					TelaErroCadastro erro = new TelaErroCadastro();

					erro.setVisible(true);

				}

			}
		});

		labelTelefone2.setText("Telefone Pessoal");

		labelTelefone1.setText("Telefone Residencial");

		campoEmail.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				campoEmailActionPerformed(evt);
			}
		});

		labelEmail.setText("E-mail");

		labelContato.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
		labelContato.setText("Contato");

		campoCidade.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				campoCidadeActionPerformed(evt);
			}
		});

		labelCidade.setText("Cidade");

		campoRua.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				campoRuaActionPerformed(evt);
			}
		});

		labelRua.setText("Rua");

		labelEndereco.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
		labelEndereco.setText("Endereco");

		campoUF.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
				"", "AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES", "GO", "MA",
				"MG", "MS", "MT", "PA", "PB", "PE", "PI", "PR", "RJ", "RN",
				"RO", "RS", "SC", "SE", "SP", "TO" }));

		labelUF.setText("UF");

		labelBairro.setText("Bairro");

		labelCEP.setText("CEP");

		campoSobrenome.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				campoSobrenomeActionPerformed(evt);
			}
		});

		labelSobrenome.setText("Sobrenome");

		campoNome.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				campoNomeActionPerformed(evt);
			}
		});

		labelNome.setText("Nome");

		labelRG.setText("RG");

		campoCargo.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				campoCargoActionPerformed(evt);
			}
		});

		labelCPF.setText("CPF");

		labelCargo.setText("Cargo");

		labelDadosPessoais.setFont(new java.awt.Font("Tahoma", 1, 13)); // NOI18N
		labelDadosPessoais.setText("Dados Pessoais");

		setJMenuBar(barraMenu);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		layout.setHorizontalGroup(
			layout.createParallelGroup(Alignment.TRAILING)
				.addGroup(layout.createSequentialGroup()
					.addGap(6)
					.addGroup(layout.createParallelGroup(Alignment.TRAILING)
						.addGroup(Alignment.LEADING, layout.createSequentialGroup()
							.addGroup(layout.createParallelGroup(Alignment.LEADING)
								.addComponent(labelEmail)
								.addComponent(campoEmail, GroupLayout.PREFERRED_SIZE, 309, GroupLayout.PREFERRED_SIZE))
							.addGap(18)
							.addGroup(layout.createParallelGroup(Alignment.LEADING)
								.addComponent(campoTelefone1, GroupLayout.PREFERRED_SIZE, 236, GroupLayout.PREFERRED_SIZE)
								.addComponent(labelTelefone1))
							.addGap(39)
							.addGroup(layout.createParallelGroup(Alignment.LEADING)
								.addComponent(labelTelefone2)
								.addGroup(layout.createParallelGroup(Alignment.TRAILING)
									.addGroup(layout.createSequentialGroup()
										.addComponent(botaoVoltar)
										.addGap(18)
										.addComponent(botaoSalvar, GroupLayout.PREFERRED_SIZE, 112, GroupLayout.PREFERRED_SIZE))
									.addComponent(campoTelefone2, GroupLayout.PREFERRED_SIZE, 237, GroupLayout.PREFERRED_SIZE))))
						.addGroup(layout.createParallelGroup(Alignment.TRAILING)
							.addGroup(layout.createSequentialGroup()
								.addGroup(layout.createParallelGroup(Alignment.LEADING)
									.addGroup(layout.createSequentialGroup()
										.addGroup(layout.createParallelGroup(Alignment.LEADING)
											.addComponent(labelCidade)
											.addComponent(campoCidade, GroupLayout.PREFERRED_SIZE, 229, GroupLayout.PREFERRED_SIZE))
										.addGap(44)
										.addGroup(layout.createParallelGroup(Alignment.LEADING)
											.addComponent(labelUF)
											.addComponent(campoUF, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
									.addComponent(labelEndereco)
									.addComponent(labelRua)
									.addComponent(labelContato)
									.addComponent(labelDadosPessoais)
									.addGroup(layout.createSequentialGroup()
										.addGap(352)
										.addGroup(layout.createParallelGroup(Alignment.LEADING)
											.addComponent(campoBairro, GroupLayout.PREFERRED_SIZE, 255, GroupLayout.PREFERRED_SIZE)
											.addComponent(labelBairro))))
								.addGap(18)
								.addGroup(layout.createParallelGroup(Alignment.LEADING)
									.addGroup(layout.createSequentialGroup()
										.addComponent(labelCEP)
										.addPreferredGap(ComponentPlacement.RELATED, 192, Short.MAX_VALUE))
									.addComponent(campoCEP, GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)))
							.addComponent(campoRua, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 839, Short.MAX_VALUE)
							.addGroup(layout.createSequentialGroup()
								.addGroup(layout.createParallelGroup(Alignment.LEADING, false)
									.addComponent(labelRG)
									.addComponent(labelNome)
									.addComponent(campoRG, GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
									.addComponent(campoNome))
								.addGap(41)
								.addGroup(layout.createParallelGroup(Alignment.LEADING)
									.addComponent(labelSobrenome)
									.addGroup(layout.createSequentialGroup()
										.addGroup(layout.createParallelGroup(Alignment.LEADING)
											.addComponent(campoCPF, GroupLayout.PREFERRED_SIZE, 253, GroupLayout.PREFERRED_SIZE)
											.addComponent(labelCPF))
										.addGap(18)
										.addGroup(layout.createParallelGroup(Alignment.LEADING)
											.addComponent(campoCargo, GroupLayout.DEFAULT_SIZE, 242, Short.MAX_VALUE)
											.addComponent(labelCargo)))
									.addComponent(campoSobrenome, GroupLayout.PREFERRED_SIZE, 513, GroupLayout.PREFERRED_SIZE)))))
					.addGap(80))
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
					.addContainerGap()
					.addComponent(labelDadosPessoais)
					.addGap(18)
					.addGroup(layout.createParallelGroup(Alignment.BASELINE)
						.addComponent(labelNome)
						.addComponent(labelSobrenome))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(layout.createParallelGroup(Alignment.BASELINE)
						.addComponent(campoNome, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(campoSobrenome, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(13)
					.addGroup(layout.createParallelGroup(Alignment.BASELINE)
						.addComponent(labelRG)
						.addComponent(labelCPF)
						.addComponent(labelCargo))
					.addGap(4)
					.addGroup(layout.createParallelGroup(Alignment.BASELINE)
						.addComponent(campoRG, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(campoCPF, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(campoCargo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(27)
					.addComponent(labelEndereco)
					.addGap(18)
					.addComponent(labelRua)
					.addGap(12)
					.addComponent(campoRua, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addGap(13)
					.addGroup(layout.createParallelGroup(Alignment.LEADING)
						.addGroup(layout.createSequentialGroup()
							.addGroup(layout.createParallelGroup(Alignment.BASELINE)
								.addComponent(labelCidade, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE)
								.addComponent(labelUF, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addComponent(labelBairro, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE)
								.addComponent(labelCEP, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(layout.createParallelGroup(Alignment.BASELINE)
								.addComponent(campoCidade, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(campoUF, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
						.addGroup(layout.createSequentialGroup()
							.addGap(22)
							.addGroup(layout.createParallelGroup(Alignment.BASELINE)
								.addComponent(campoBairro, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(campoCEP, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
					.addGap(18)
					.addGroup(layout.createParallelGroup(Alignment.TRAILING)
						.addGroup(layout.createSequentialGroup()
							.addComponent(labelContato)
							.addGap(18)
							.addComponent(labelEmail))
						.addGroup(layout.createParallelGroup(Alignment.BASELINE)
							.addComponent(labelTelefone2)
							.addComponent(labelTelefone1)))
					.addPreferredGap(ComponentPlacement.RELATED)
					.addGroup(layout.createParallelGroup(Alignment.BASELINE)
						.addComponent(campoTelefone2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(campoEmail, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(campoTelefone1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(39)
					.addGroup(layout.createParallelGroup(Alignment.LEADING)
						.addComponent(botaoSalvar, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
						.addComponent(botaoVoltar))
					.addGap(131))
		);
		getContentPane().setLayout(layout);

		pack();
	}// </editor-fold>//GEN-END:initComponents

	private void campoEmailActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_campoEmailActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_campoEmailActionPerformed

	private void campoCidadeActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_campoCidadeActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_campoCidadeActionPerformed

	private void campoRuaActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_campoRuaActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_campoRuaActionPerformed

	private void campoSobrenomeActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_campoSobrenomeActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_campoSobrenomeActionPerformed

	private void campoNomeActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_campoNomeActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_campoNomeActionPerformed

	private void campoCargoActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_campoCargoActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_campoCargoActionPerformed

	private javax.swing.JMenuBar barraMenu;
	private javax.swing.JButton botaoVoltar;
	private javax.swing.JButton botaoSalvar;
	private javax.swing.JTextField campoBairro;
	private javax.swing.JTextField campoCEP;
	private javax.swing.JTextField campoCPF;
	private javax.swing.JTextField campoCargo;
	private javax.swing.JTextField campoCidade;
	private javax.swing.JTextField campoEmail;
	private javax.swing.JTextField campoNome;
	private javax.swing.JTextField campoRG;
	private javax.swing.JTextField campoRua;
	private javax.swing.JTextField campoSobrenome;
	private javax.swing.JTextField campoTelefone1;
	private javax.swing.JTextField campoTelefone2;
	private javax.swing.JComboBox campoUF;
	private javax.swing.JLabel labelBairro;
	private javax.swing.JLabel labelCEP;
	private javax.swing.JLabel labelCPF;
	private javax.swing.JLabel labelCargo;
	private javax.swing.JLabel labelCidade;
	private javax.swing.JLabel labelContato;
	private javax.swing.JLabel labelDadosPessoais;
	private javax.swing.JLabel labelEmail;
	private javax.swing.JLabel labelEndereco;
	private javax.swing.JLabel labelNome;
	private javax.swing.JLabel labelRG;
	private javax.swing.JLabel labelRua;
	private javax.swing.JLabel labelSobrenome;
	private javax.swing.JLabel labelTelefone1;
	private javax.swing.JLabel labelTelefone2;
	private javax.swing.JLabel labelUF;
	private final Action action = new SwingAction();

	// End of variables declaration//GEN-END:variables
	private class SwingAction extends AbstractAction {
		public SwingAction() {
			putValue(NAME, "SwingAction");
			putValue(SHORT_DESCRIPTION, "Some short description");
		}

		public void actionPerformed(ActionEvent e) {
		}
	}
}
